package com.example.farm.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.farm.Bean.Land;
import com.example.farm.Bean.Product;
import com.example.farm.mapper.ProductMapper;
import com.example.farm.service.ProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 姚
 * @since 2023-04-15
 */
@Service
@Transactional
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {


    @Autowired
    private ProductMapper productMapper;

    @Override
    public int updateProduct(Product product) {
        if (product.getUid() == null){
            return productMapper.insert(product);
        }else {

            UpdateWrapper<Product> updateWrapper = new UpdateWrapper<>();
            updateWrapper.eq("uid",product.getUid());
            updateWrapper.set("Quantity",product.getQuantity());

            return productMapper.update(product,updateWrapper);
        }
    }

    @Override
    public ArrayList<Product> selectAll() {
        return productMapper.selectAll();
    }

    @Override
    public int calculateData(Product product) {
        return 0;
    }
}
